package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao {
    private static Teacher[] stus = new Teacher[5];
    public static Teacher[] findAllStudent() {
        return stus;
    }

    public static void deleteTeacherById(String delId) {
        int index = getIndex(delId);
        stus[index]= null;
    }

    private static int getIndex(String id) {
        int index = -1;
        for (int i = 0; i <stus.length ; i++) {
            Teacher stu = stus[i];
            if (stu != null && stu.getId().equals(id)){
                index = i ;
                break;
            }
        }
        return index;
    }

    public static void updateStudent(String updateId, Teacher newStu) {
        int index = getIndex(updateId);
        stus[index]=newStu;
    }

    public static Teacher[] findAllTeacher() {
        return stus;
    }

    public static boolean addTeacher(Teacher stu) {
        int index = -1;
        for (int i = 0; i <stus.length ; i++) {
            Teacher teacher = stus[i];
            if (teacher == null){
                index = i;
                break;
            }

        }
        if (index==-1){
            return false;
        }else {
            stus[index]=stu;
            return true;
        }
    }
}
